import { Checkbox } from "antd";
import React from "react";
import { useState } from "react";

/**
 * @description 封装checkbox组件，使其返回"1"或者"0"
 */

const XxCheckbox = ({ onChange, children, defaultChecked = false, ...props }) => {
    const [value, setValue] = useState(defaultChecked);
    const handleChange = (v) => {
        console.log("checkbox组件的onChange接收到的值：", v.target.checked)
        const newVal = v.target.checked;
        setValue(newVal);
        if (onChange) {
            onChange(newVal ? "1" : "0")
        }
    }
    return <Checkbox
        {...props}
        checked={value}
        onChange={value => handleChange(value)}
    >{children}</Checkbox>
}

export default XxCheckbox;